logo

The best IT Trainig Institute In Gurgaon

Execute Failed Test Cases in Selenium

Steps to Run the Method
  • Create a New Class in a General package Name it For.eg " learnerTest " etc... and Write the given below code
package asc;

import org.testng.Assert;
import org.testng.annotations.Test;

import common.BaseTest;
import common.Retry;

public class learnersDemoTest extends BaseTest {

    @Test(retryAnalyzer = Retry.class)
    public void launchApp()
    {
        driver.get("https://ittrainingclasses.in/");
        Assert.assertTrue(false);
    }
}
                    
  • And Then Create new class in Common package name it " Retry " and write given below Code
package common;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class Retry implements IRetryAnalyzer {

  private int retryCount = 0;
  private static final int maxRetryCount = 3;


  public boolean retry(ITestResult result) {
    if (retryCount < maxRetryCount) {
      retryCount++;
      return true;
    }
    return false;
  }
}
                    
  • And then Create one more New Class in common package name it " RetryListener " and Write given below Code
package common;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

public class RetryListener implements IAnnotationTransformer {

    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, MettestMethod) {
        annotation.setRetryAnalyzer(Retry.class);
    }
    
}
            
  • After that Create one Test suite or XML file and Change as per given below Code
< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
< suite name="Retry Listeners test">
< listeners>
< listener class-name="common.RetryListener" />
< /listeners>
  < test name="Functionl Testing">
  < parameter name="browser" value="Chrome">< /parameter>
    < classes>
      < class name="asc.learnersDemoTest"/>
      < class name="asc.VerifyTitle"/>
    < /classes>
  < /test> 
< /suite> 
                
  • After all this process happen then Run the Test Suite